class Admin::WebsController < Admin::BaseController
  layout   'base'
  # GET /admin_webs
  # GET /admin_webs.xml
  def index
    @search = Web.new_search(params[:search])
    unless params[:keywords].blank?
      keywords = split_keyword(params[:keywords])
      keywords.each do |keyword|
        unless keyword.blank?
          @search.conditions.group do |g|
            g.or_body_like = keyword
            g.or_body_contains  = keyword
          end
        end
      end
    end
    @search.order_as = "desc"
    @search.order_by = ['sort','updated_at']
    @webs = @search.all.paginate(:page => params[:page] , :per_page => 20)
   

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @webs }
    end
  end

  # GET /admin_webs/1
  # GET /admin_webs/1.xml
  def show
    @web = Web.find(params[:id])
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @web }
    end
  end

  # GET /admin_webs/new
  # GET /admin_webs/new.xml
  def new
    @web = Web.new
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @web }
    end
  end

  # GET /admin_webs/1/edit
  def edit
    @web = Web.find(params[:id])
  end

  # POST /admin_webs
  # POST /admin_webs.xml
  def create
    @web = Web.new(params[:web])
    respond_to do |format|
      if @web.save
        flash[:notice] = 'Web was successfully created.'
        format.html { redirect_to admin_web_path(@web) }
        format.xml  { render :xml => @web, :status => :created, :location => @web }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @web.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /admin_webs/1
  # PUT /admin_webs/1.xml
  def update
    @web = Web.find(params[:id])
    respond_to do |format|
      if @web.update_attributes(params[:web])
        flash[:notice] = 'Web was successfully updated.'
        format.html { redirect_to  admin_web_path(@web) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @web.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /admin_webs/1
  # DELETE /admin_webs/1.xml
  def destroy
    @web = Web.find(params[:id])
    @web.destroy

    respond_to do |format|
      format.html { redirect_to(admin_webs_url) }
      format.xml  { head :ok }
    end
  end
  
  
end
